home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
VideoFolder 1.0a
/
Source
/
VideoFolderWindow.cp
< prev
next >
Wrap
Text File
|
1996-06-21
|
7KB
|
316 lines
// ===========================================================================
// VideoFolderWindow.cp
// ===========================================================================
#include "VideoFolderWindow.h"
#include "FSSpecPane.h"
#include "MoreFilesExtras.h"
#include "SequenceGrabberPane.h"
#include "UStandardFile.h"
VideoFolderWindow* VideoFolderWindow::CreateVideoFolderWindowStream(LStream *inStream)
{
return new VideoFolderWindow ( inStream );
}
VideoFolderWindow::VideoFolderWindow( LStream *inStream) :
mDefaultOutline ( nil ),
LWindow ( inStream )
{
}
VideoFolderWindow::~VideoFolderWindow()
{
delete mDefaultOutline;
}
void VideoFolderWindow::DoGrab ( )
{
Try_ {
Rect frameRect;
mSequenceGrabberPane->CalcPortFrameRect ( frameRect );
LGWorld image ( frameRect, 8, useTempMem );
mSequenceGrabberPane->Grab();
mSequenceGrabberPane->DrawSelf();
image.BeginDrawing ();
mSequenceGrabberPane->DrawSelf();
image.EndDrawing();
FSSpecPane* destFSSpecPane = dynamic_cast<FSSpecPane*> ( FindPaneByID ( 'DSTF' ) );
if ( destFSSpecPane )
{
FSSpec spec;
destFSSpecPane->GetFSSpec ( spec );
CFinderIconPicture iconMaker ( spec.vRefNum, spec.parID );
iconMaker.AcceptPict ( image.GetMacGWorld() );
}
}
Catch_( inErr )
{
}
}
void VideoFolderWindow::DoSequenceGrabberSetup()
{
mSequenceGrabberPane->DoSetupDialog();
}
void
VideoFolderWindow::FindCommandStatus(
CommandT inCommand,
Boolean &outEnabled,
Boolean &outUsesMark,
Char16 &outMark,
Str255 outName)
{
switch (inCommand)
{
// Return menu item status according to command messages.
// Any that you don't handle will be passed to LApplication
case cmd_GrabFrame: // EXAMPLE
outEnabled = true; // enable the New command
break;
case cmd_GrabInterval:
outEnabled = true;
break;
default:
LCommander::FindCommandStatus(inCommand, outEnabled,
outUsesMark, outMark, outName);
break;
}
}
void VideoFolderWindow::FinishCreate ( )
{
LWindow::FinishCreate();
mSequenceGrabberPane = dynamic_cast<SequenceGrabberPane*> ( FindPaneByID ( 'sgrb' ) );
ThrowIfNil_( mSequenceGrabberPane );
LControl* grabButton = dynamic_cast<LControl*> ( FindPaneByID( 'GRAB' ) );
if (grabButton != nil)
mDefaultOutline = new LDefaultOutline(grabButton);
UReanimator::LinkListenerToControls ( this, this, GetPaneID() );
StartListening();
StartIdling ();
// mFinderIconPicture = nil;
// mDestinationSpec.vRefNum = 0;
// mDestinationSpec.parID = 0;
Boolean liveUpdate = true;
LPane* liveUpdateControl = dynamic_cast<LPane*> ( FindPaneByID ( 'LIVE' ) );
if ( liveUpdateControl )
liveUpdate = liveUpdateControl->GetValue() != 0;
mSequenceGrabberPane->SetLiveUpdate ( liveUpdate );
unsigned long nextUpdateSecs;
GetDateTime ( & nextUpdateSecs );
nextUpdateSecs += 30;
mNextUpdateControl = dynamic_cast<LPane*> ( FindPaneByID ( 'NEXT' ) );
if ( mNextUpdateControl )
mNextUpdateControl->SetValue ( nextUpdateSecs );
mUpdateIntervalControl = dynamic_cast<LStdPopupMenu*> ( FindPaneByID ( 'INTV' ) );
}
unsigned long intervals[] = { 60, 300, 15*60, 60*60, 4*60*60, 12*60*60, 24*60*60 };
unsigned long VideoFolderWindow::GetUpdateInterval ( ) const
{ unsigned long result = 60 * 5; // default to every 5 minutes
if ( mUpdateIntervalControl )
{
short value = mUpdateIntervalControl->GetValue();
if ( 1 <= value && value <= sizeof( intervals ) )
result = intervals[ value - 1 ];
}
return result;
}
void VideoFolderWindow::SetUpdateInterval ( unsigned long interval )
{
if ( mUpdateIntervalControl )
{ short value = 0;
while ( value < sizeof( intervals ) && intervals[ value ] < interval )
value ++;
mUpdateIntervalControl->SetValue( interval + 1 );
}
}
Boolean
VideoFolderWindow::HandleKeyPress(
const EventRecord &inKeyEvent)
{
Boolean keyHandled = false;
LControl *keyButton = nil;
switch (inKeyEvent.message & charCodeMask) {
case char_Enter:
case char_Return:
keyButton = dynamic_cast<LControl*> ( FindPaneByID( 'GRAB' ) );
break;
case char_Escape:
if ((inKeyEvent.message & keyCodeMask) == vkey_Escape) {
keyButton = dynamic_cast<LControl*> ( FindPaneByID( 2 ) );
}
break;
default:
if (UKeyFilters::IsCmdPeriod(inKeyEvent)) {
keyButton = dynamic_cast<LControl*> ( FindPaneByID( 2 ) );
} else {
keyHandled = LWindow::HandleKeyPress(inKeyEvent);
}
break;
}
if (keyButton != nil) {
keyButton->SimulateHotSpotClick(kControlButtonPart);
keyHandled = true;
}
return keyHandled;
}
void VideoFolderWindow::ListenToMessage( MessageT inMessage,
void *ioParam)
{
switch ( inMessage )
{
case cmd_GrabFrame:
DoGrab ( );
break;
case cmd_SequenceGrabberSetup:
DoSequenceGrabberSetup();
break;
case cmd_LiveUpdateControl:
LPane* liveUpdate = dynamic_cast<LPane*> ( FindPaneByID ( 'LIVE' ) );
if ( liveUpdate )
mSequenceGrabberPane->SetLiveUpdate ( liveUpdate->GetValue() != 0 );
break;
case cmd_GrabInterval:
if ( mNextUpdateControl )
{ unsigned long now;
GetDateTime ( & now );
unsigned long nextUpdate = now + GetUpdateInterval();
mNextUpdateControl->SetValue ( nextUpdate );
}
break;
case cmd_SetDestination:
StandardFileReply reply;
FSSpecPane* destFSSpecPane = dynamic_cast<FSSpecPane*> ( FindPaneByID ( 'DSTF' ) );
if ( destFSSpecPane )
{
destFSSpecPane->GetFSSpec ( reply.sfFile );
if ( UStandardFile::GetDirectory ( reply ) )
{
reply.sfFile.name[0] = 0;
destFSSpecPane->SetFSSpec ( reply.sfFile );
}
}
break;
}
}
Boolean VideoFolderWindow::ObeyCommand(
CommandT inCommand,
void *ioParam )
{
Boolean cmdHandled = true;
switch (inCommand) {
// Deal with command messages (defined in PP_Messages.h).
// Any that you don't handle will be passed to LApplication
case cmd_GrabFrame:
DoGrab ();
break;
case cmd_SequenceGrabberSetup:
DoSequenceGrabberSetup();
break;
case cmd_LiveUpdateControl:
LPane* liveUpdate = dynamic_cast<LPane*> ( FindPaneByID ( 'LIVE' ) );
if ( liveUpdate )
mSequenceGrabberPane->SetLiveUpdate ( liveUpdate->GetValue() != 0 );
break;
default:
cmdHandled = LCommander::ObeyCommand(inCommand, ioParam);
break;
}
return cmdHandled;
}
void VideoFolderWindow::SpendTime( const EventRecord &inMacEvent)
{
if ( mNextUpdateControl )
{ unsigned long now;
GetDateTime ( & now );
if ( mNextUpdateControl->GetValue() < now )
{
DoGrab ( );
mNextUpdateControl->SetValue ( now + GetUpdateInterval() );
}
}
}
#if 0
void VideoFolderWindow::GetDestination ( FSSpec& outSpec )
{
outSpec = mDestinationSpec;
}
void VideoFolderWindow::SetDestination ( const FSSpec& inSpec )
{
// delete mFinderIconPicture;
// mFinderIconPicture = nil;
mDestinationSpec = inSpec;
long dirID;
Boolean isDirectory;
if ( GetDirectoryID( mDestinationSpec.vRefNum, mDestinationSpec.parID, (StringPtr) "\p", & dirID, & isDirectory ) == noErr )
mFinderIconPicture = new CFinderIconPicture ( mDestinationSpec.vRefNum, dirID );
}
#endif